﻿if (self.containsFocus == true) {
    var budgetItems = ref.BudgetItems.getValue();
    var fiscalYear = ref.fiscalYear.getValue();

    var vm = this.lookupViewModel();
    vm.set('NebulogyForm.companySection.budgetItem', budgetItems);
    var url = PAI.application.serviceUrl;

    var itemAccount = "";
    var jaConst = "";
    var lrConst = "";

    ref.datagrid2.store.removeAll();
    ref.datagrid7.store.removeAll();
    ref.datagrid3.store.removeAll();
    ref.datagrid4.store.removeAll();
    ref.datagrid6.store.removeAll();
    ref.horizonGrid.store.removeAll();

    ref.datagrid3.getColumns()[0].getEditor().store.data.removeAll();
    ref.datagrid4.getColumns()[0].getEditor().store.data.removeAll();
    ref.datagrid6.getColumns()[0].getEditor().store.data.removeAll();
    ref.horizonGrid.getColumns()[0].getEditor().store.data.removeAll();

    Ext.PAIRest.request({
        ns: PAI.application.serviceUrl,
        url: 'jlr-rest/api/budgetRelationItem/getBudgetItemParentNode',
        method: "POST",
        async: false,
        data: {
            budgetItemId: budgetItems,
            valid: 'Y',
            yearVal: fiscalYear.split('_')[0]
        },
        success: function (data) {
            if (data.budgetRelationItemF05RespS01 !== null || data.budgetRelationItemF05RespS02 !== null || data.budgetRelationItemF05RespS03 !== null) {
                var pa = [];
                for (var i = 0; i < data.budgetRelationItemF05RespS01.length; i++) {
                    pa.push({
                        ID: data.budgetRelationItemF05RespS01[i].id,
                        ProjectActivity: data.budgetRelationItemF05RespS01[i].projectActivty
                    });
                }

                vm.set('NebulogyForm.ProjectActivityList', pa);

                for (var x = 0; x < data.budgetRelationItemF05RespS02.length; x++) {
                    itemAccount = data.budgetRelationItemF05RespS02[x].glAccount;
                }
                for (var j = 0; j < data.budgetRelationItemF05RespS03.length; j++) {
                    jaConst = data.budgetRelationItemF05RespS03[j].costCenterJa;
                    lrConst = data.budgetRelationItemF05RespS03[j].costCenterLr;
                }
            }

            ref.datagrid4.JACostCenter = jaConst;
            ref.datagrid4.LRCostCenter = lrConst;

            //给GLaccount赋值
            vm.set('NebulogyForm.GeneralInformation.Account', itemAccount);
        }
    });
}